cells=[2 12 13 15 17 37 52 66 80 85 86 155 168 203 212 223 224 226 230 264 303 317 401 419 427 429 444 477 482 562];
snips={};
for tnd=1:7
    cnt=1;
    ons=find(diff(proj_meta(cur_site).raw_data(vis_res(nnd,1),tnd).velP_ind)==1);
    for gnd=1:length(ons)
        if ons(gnd)-low_t>0 && ons(gnd)+high_t<length(proj_meta(cur_site).raw_data(vis_res(nnd,1),tnd).velP_ind)
            cur_low=ons(gnd)-low_t:ons(gnd);
            cur_high=ons(gnd)+1:ons(gnd)+high_t;
            if sum(proj_meta(cur_site).raw_data(vis_res(nnd,1),tnd).velP_ind(cur_low))==0 && sum(proj_meta(cur_site).raw_data(vis_res(nnd,1),tnd).velP_ind(cur_high))==high_t
                if sum(proj_meta(cur_site).raw_data(vis_res(nnd,1),tnd).velM_ind(cur_low-4:cur_high+4))==0
                    snips{tnd}(cnt,:)=[cur_low cur_high];
                    cnt=cnt+1;
                end
            end
        end
    end
end
for tnd=1:7
    cnt=0;
    for und=1:size(snips{tnd},1)
        cor_snips{tnd}(cnt+1:cnt+26)=snips{tnd}(und,:);
        cnt=cnt+26;
    end
    lens(tnd)=size(cor_snips{tnd},2);
end
for tnd=1:7
    cor_snips{tnd}=cor_snips{tnd}(1:min(lens));
end

% res=[];
% cells=66;
% for tnd=1:7
%     filt=ftfil(proj_meta(cur_site).raw_data(1,tnd).velP_raw,30,0,10);
%     runP=smooth2(filt,3);
%     Y=runP(cor_snips{tnd})';
%     data=[];
%     cnt=1;
%     for gnd=1:4
%         for fnd=1:length(proj_meta(cur_site).raw_data(gnd,tnd).smoothed_ROIs);
%             raw=proj_meta(cur_site).raw_data(gnd,tnd).smoothed_ROIs(fnd).activity;
%             data(:,cnt)=raw/median(raw);
%             cnt=cnt+1;
%         end
%     end
%     X=data(cor_snips{tnd},:);
%     for knd=1:size(X,2)
%         res(knd,tnd)=corr(X(:,knd),Y);
%     end
% end



% figure;
% for tnd=1:7
%     filt=ftfil(proj_meta(cur_site).raw_data(1,tnd).velP_raw,30,0,10);
%     runP=smooth2(filt,3);
% %     Y=runP(all_wind(tnd)-4:all_wind(tnd)+(win_size-1)-4)';
% %     Y=runP(cor_snips{tnd})';
% %     Y=runP([fb_frames(1,1):fb_frames(2,1) fb_frames(1,2):fb_frames(2,2)])';
%     Y=runP;
%     data=[];
%     cnt=1;
%     for gnd=1:4
%         for fnd=1:length(proj_meta(cur_site).raw_data(gnd,tnd).smoothed_ROIs);
%             raw=proj_meta(cur_site).raw_data(gnd,tnd).smoothed_ROIs(fnd).activity;
%             data(:,cnt)=raw/median(raw);
%             cnt=cnt+1;
%         end
%     end
% %     X=data([fb_frames(1,1):fb_frames(2,1) fb_frames(1,2):fb_frames(2,2)],cells);
%     X=data(:,cells);
%     subplot(7,1,tnd)
%     plot(X,'r')
%     hold on
%     plot(Y*50,'k','linewidth',1.5)
%     
%     ylim([0 5])
% end

% figure;
% for tnd=1:7
%     subplot(7,1,tnd)
%     hold on
%     plot(proj_meta(cur_site).raw_data(1,tnd).velP_raw)
%     ylim([0 0.2])
% end